home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Visual Database / Visual dBase v5.5 / SAMPLES1.PAK / CONTACT.WFM < prev    next >
Text File  |  1995-07-18  |  18KB  |  653 lines

  1. *******************************************************************************
  2. *  PROGRAM:      Contact.wfm
  3. *
  4. *  WRITTEN BY:   Borland Samples Group
  5. *
  6. *  DATE:         5/93
  7. *
  8. *  UPDATED:      5/95
  9. *
  10. *  REVISION:     $Revision:   2.63  $
  11. *
  12. *  VERSION:      Visual dBASE
  13. *
  14. *  DESCRIPTION:  The form in this file displays a list of companies and
  15. *                lets you view the contacts for those companies in a separate
  16. *                form.  It contains a listbox of company names, 3 radiobuttons
  17. *                indicating the company's type, and pushbuttons that allow you
  18. *                to see the form with contacts for the currently hightlighted
  19. *                company or leave the contact form.
  20. *                The third page of this form allows you to create a link to
  21. *                Word 6 using Ole Automation, and, using the Mail Merge feature
  22. *                of Word, create letters to the companies in the Company table.
  23. *
  24. *  PARAMETERS:   None
  25. *
  26. *  CALLS:        Buttons.cc      (Custom Controls file)
  27. *                Contact.qbe     (View of tables)
  28. *
  29. *  USAGE:        DO Contact.wfm
  30. *
  31. *******************************************************************************
  32. #include <Messdlg.h>
  33.  
  34. * Word basic function parameter values
  35. #define REPORT_ERRORS           1
  36. #define TO_FILE                 0
  37. #define TO_PRINTER              1
  38. #define MERGE_ALL               0
  39. #define MERGE_RANGE             1
  40. #define NO_SAVE                 2
  41. #define PRINT_PREVIEW_OFF       0
  42. #define PRINT_PREVIEW_ON        1
  43.  
  44.  
  45. shell(.F.)
  46. create session
  47. set talk off
  48. set ldCheck off
  49.  
  50. ** END HEADER -- do not remove this line*
  51. * Generated on 07/11/95
  52. *
  53. parameter bModal
  54. local f
  55. f = new CONTACTFORM()
  56. if (bModal)
  57.    f.mdi = .F. && ensure not MDI
  58.    f.ReadModal()
  59. else
  60.    f.Open()
  61. endif
  62. CLASS CONTACTFORM OF FORM
  63.    Set Procedure To &_dbwinhome.samples\BUTTONS.CC additive
  64.    this.OnOpen = CLASS::FORM_ONOPEN
  65.    this.EscExit = .F.
  66.    this.Width = 55.666
  67.    this.OnClose = CLASS::FORM_ONCLOSE
  68.    this.View = "CONTACT.QBE"
  69.    this.Text = "Contact"
  70.    this.Top = 1.1172
  71.    this.Maximize = .F.
  72.    this.Minimize = .F.
  73.    this.Left = 25
  74.    this.ColorNormal = "BTNTEXT/BTNFACE"
  75.    this.MousePointer = 1
  76.    this.Height = 12.5293
  77.    this.PageNo = 1
  78.  
  79.    DEFINE TEXT LISTTEXT OF THIS;
  80.        PROPERTY;
  81.          Width 17.166,;
  82.          FontBold .F.,;
  83.          Text "Company Name:",;
  84.          Top 0.8262,;
  85.          Left 0.5,;
  86.          ColorNormal "B/BtnFace",;
  87.          PageNo 0,;
  88.          Height 1.1143
  89.  
  90.    DEFINE LISTBOX COMPANYLIST OF THIS;
  91.        PROPERTY;
  92.          DataSource "FIELD COMPANY->COMPANY",;
  93.          Width 24.833,;
  94.          FontBold .F.,;
  95.          ID 800,;
  96.          Top 2,;
  97.          ColorHighLight "W+/B",;
  98.          Left 0.5,;
  99.          ColorNormal "N/W*",;
  100.          Height 7
  101.  
  102.    DEFINE TEXT TYPETEXT OF THIS;
  103.        PROPERTY;
  104.          Width 17.166,;
  105.          FontBold .F.,;
  106.          Text "Company Type:",;
  107.          Top 2.1797,;
  108.          Left 0.5,;
  109.          ColorNormal "B/BtnFace",;
  110.          PageNo 2,;
  111.          Height 0.9961
  112.  
  113.    DEFINE RADIOBUTTON COMPANYTYPE1 OF THIS;
  114.        PROPERTY;
  115.          Width 8,;
  116.          Group .T.,;
  117.          Text "OEM",;
  118.          Top 2.1758,;
  119.          Enabled .F.,;
  120.          DataLink "COMPANY->TYPE",;
  121.          Left 17,;
  122.          ColorNormal "N/BtnFace",;
  123.          PageNo 2,;
  124.          Height 1
  125.  
  126.    DEFINE RADIOBUTTON COMPANYTYPE2 OF THIS;
  127.        PROPERTY;
  128.          Width 7,;
  129.          Group .F.,;
  130.          Text "ISV",;
  131.          Top 2.1973,;
  132.          Enabled .F.,;
  133.          DataLink "COMPANY->TYPE",;
  134.          Left 26,;
  135.          ColorNormal "N/BtnFace",;
  136.          PageNo 2,;
  137.          Height 0.9775
  138.  
  139.    DEFINE RADIOBUTTON COMPANYTYPE3 OF THIS;
  140.        PROPERTY;
  141.          Width 8.002,;
  142.          Group .F.,;
  143.          Text "VAR",;
  144.          Top 2.1973,;
  145.          Enabled .F.,;
  146.          DataLink "COMPANY->TYPE",;
  147.          Left 33.8311,;
  148.          ColorNormal "N/BtnFace",;
  149.          PageNo 2,;
  150.          Height 0.9775
  151.  
  152.    DEFINE TEXT CONTACTTEXT OF THIS;
  153.        PROPERTY;
  154.          Width 19.833,;
  155.          FontBold .F.,;
  156.          Text "Contact:",;
  157.          Top 0.8262,;
  158.          Left 28.5,;
  159.          ColorNormal "B/BtnFace",;
  160.          Height 1.1143
  161.  
  162.    DEFINE ENTRYFIELD CONTACTENTRY OF THIS;
  163.        PROPERTY;
  164.          Width 26.166,;
  165.          FontBold .F.,;
  166.          Function "S80",;
  167.          Top 2,;
  168.          ColorHighLight "B+/W*",;
  169.          Enabled .F.,;
  170.          DataLink "CONTACT->CONTACT",;
  171.          Left 28.5,;
  172.          ColorNormal "B/W*",;
  173.          Height 1.1172
  174.  
  175.    DEFINE TEXT NOTESTEXT OF THIS;
  176.        PROPERTY;
  177.          Width 11.8359,;
  178.          FontBold .F.,;
  179.          Text "Notes:",;
  180.          Top 3.5,;
  181.          Left 28.6641,;
  182.          ColorNormal "B/BtnFace",;
  183.          Height 0.8516
  184.  
  185.    DEFINE EDITOR EDITNOTES OF THIS;
  186.        PROPERTY;
  187.          Width 26.166,;
  188.          FontBold .F.,;
  189.          CUATab .T.,;
  190.          Modify .F.,;
  191.          Top 4.5,;
  192.          DataLink "CONTACT->NOTES",;
  193.          Left 28.5,;
  194.          ColorNormal "N/W*",;
  195.          Height 4.4395
  196.  
  197.    DEFINE CLOSEBUTTON CONTACTCLOSEBUTTON OF THIS;
  198.        PROPERTY;
  199.          Width 14.1689,;
  200.          Group .T.,;
  201.          Top 9.6973,;
  202.          Left 40.6641,;
  203.          PageNo 0,;
  204.          Height 1.5361
  205.  
  206.    DEFINE TABBOX CONTACTTABBOX OF THIS;
  207.        PROPERTY;
  208.          DataSource 'ARRAY {"Contact","Company","Mail Merge"}',;
  209.          Width 55.666,;
  210.          FontBold .F.,;
  211.          ID 112,;
  212.          Top 11.5293,;
  213.          ColorHighLight "BtnText/BtnFace",;
  214.          ColorNormal "R/BTNFACE",;
  215.          OnSelChange CLASS::CONTACTTABBOX_ONSELCHANGE,;
  216.          Height 1
  217.  
  218.    DEFINE ENTRYFIELD COMPANYENTRY OF THIS;
  219.        PROPERTY;
  220.          Width 36.502,;
  221.          FontBold .F.,;
  222.          Top 0.8262,;
  223.          Enabled .F.,;
  224.          DataLink "COMPANY->COMPANY",;
  225.          Left 17.3311,;
  226.          ColorNormal "B/WINDOW",;
  227.          PageNo 2,;
  228.          Height 0.9971
  229.  
  230.    DEFINE RECTANGLE RECTANGLE1 OF THIS;
  231.        PROPERTY;
  232.          Width 54.333,;
  233.          Text "",;
  234.          Top 3.8223,;
  235.          Left 0.5,;
  236.          PageNo 2,;
  237.          Height 5.5303
  238.  
  239.    DEFINE TEXT STREETTEXT OF THIS;
  240.        PROPERTY;
  241.          Width 8,;
  242.          FontBold .F.,;
  243.          Text "Street:",;
  244.          Top 4.5,;
  245.          Left 2.5,;
  246.          ColorNormal "B/BtnFace",;
  247.          PageNo 2,;
  248.          Height 1.0293
  249.  
  250.    DEFINE TEXT CITYTEXT OF THIS;
  251.        PROPERTY;
  252.          Width 5.5,;
  253.          FontBold .F.,;
  254.          Text "City:",;
  255.          Top 6.8975,;
  256.          Left 2.5,;
  257.          ColorNormal "B/BtnFace",;
  258.          PageNo 2,;
  259.          Height 0.748
  260.  
  261.    DEFINE ENTRYFIELD STREET1ENTRY OF THIS;
  262.        PROPERTY;
  263.          Width 43.5,;
  264.          FontBold .F.,;
  265.          Top 4.5,;
  266.          Enabled .F.,;
  267.          DataLink "COMPANY->STREET1",;
  268.          Left 10.5,;
  269.          ColorNormal "N/WINDOW",;
  270.          PageNo 2,;
  271.          Height 1.0293
  272.  
  273.    DEFINE ENTRYFIELD STREET2ENTRY OF THIS;
  274.        PROPERTY;
  275.          Width 43.5,;
  276.          FontBold .F.,;
  277.          Top 5.5977,;
  278.          Enabled .F.,;
  279.          DataLink "COMPANY->STREET2",;
  280.          Left 10.5,;
  281.          ColorNormal "N/WINDOW",;
  282.          PageNo 2,;
  283.          Height 0.9902
  284.  
  285.    DEFINE ENTRYFIELD CITYENTRY OF THIS;
  286.        PROPERTY;
  287.          Width 14.166,;
  288.          FontBold .F.,;
  289.          Top 6.8975,;
  290.          Enabled .F.,;
  291.          DataLink "COMPANY->CITY",;
  292.          Left 10.5,;
  293.          ColorNormal "N/WINDOW",;
  294.          PageNo 2,;
  295.          Height 0.9844
  296.  
  297.    DEFINE ENTRYFIELD STATEPROVINCEENTRY OF THIS;
  298.        PROPERTY;
  299.          Width 12.6689,;
  300.          FontBold .F.,;
  301.          Top 6.8975,;
  302.          Enabled .F.,;
  303.          DataLink "COMPANY->STATE_PROV",;
  304.          Left 41.3311,;
  305.          ColorNormal "N/WINDOW",;
  306.          PageNo 2,;
  307.          Height 0.9844
  308.  
  309.    DEFINE ENTRYFIELD ZIPPOSTALENTRY OF THIS;
  310.        PROPERTY;
  311.          Width 11.666,;
  312.          FontBold .F.,;
  313.          Function "J",;
  314.          Top 8.1973,;
  315.          Enabled .F.,;
  316.          DataLink "COMPANY->ZIP_P_CODE",;
  317.          Left 26,;
  318.          ColorNormal "N/WINDOW",;
  319.          PageNo 2,;
  320.          Height 0.9775
  321.  
  322.    DEFINE TEXT STATEPROVINCETEXT OF THIS;
  323.        PROPERTY;
  324.          Width 15,;
  325.          FontBold .F.,;
  326.          Text "State/Province:",;
  327.          Top 6.8975,;
  328.          Left 26,;
  329.          ColorNormal "B/BtnFace",;
  330.          PageNo 2,;
  331.          Height 0.748
  332.  
  333.    DEFINE TEXT ZIPPOSTALTEXT OF THIS;
  334.        PROPERTY;
  335.          Width 11,;
  336.          FontBold .F.,;
  337.          Text "Zip/Postal:",;
  338.          Top 8.1973,;
  339.          Left 14,;
  340.          ColorNormal "B/BtnFace",;
  341.          PageNo 2,;
  342.          Height 0.9775
  343.  
  344.    DEFINE ENTRYFIELD COMPANYENTRY2 OF THIS;
  345.        PROPERTY;
  346.          Width 36.502,;
  347.          FontBold .F.,;
  348.          Top 0.8262,;
  349.          Enabled .F.,;
  350.          DataLink "COMPANY->COMPANY",;
  351.          Left 17.3311,;
  352.          ColorNormal "B/WINDOW",;
  353.          PageNo 3,;
  354.          Height 0.9971
  355.  
  356.    DEFINE TEXT SENDTTOEXT OF THIS;
  357.        PROPERTY;
  358.          Width 25.5,;
  359.          FontBold .F.,;
  360.          Text "Send 'Thank You' letter to ",;
  361.          Left 0.5,;
  362.          ColorNormal "B/BtnFace",;
  363.          PageNo 3,;
  364.          Height 0.7637
  365.  
  366.    DEFINE RECTANGLE RADIORECT OF THIS;
  367.        PROPERTY;
  368.          Width 55,;
  369.          FontBold .F.,;
  370.          Text "Send To: ",;
  371.          Top 4,;
  372.          Left 0.5,;
  373.          ColorNormal "B/BtnFace",;
  374.          PageNo 3,;
  375.          Height 3.5293
  376.  
  377.    DEFINE RADIOBUTTON PRINTERRADIO OF THIS;
  378.        PROPERTY;
  379.          Width 15,;
  380.          FontBold .F.,;
  381.          Group .T.,;
  382.          Text "Printer",;
  383.          Top 5,;
  384.          Left 8,;
  385.          ColorNormal "B/BtnFace",;
  386.          OnChange CLASS::PRINTERRADIO_ONCHANGE,;
  387.          PageNo 3,;
  388.          Value .T.,;
  389.          Height 1.1172
  390.  
  391.    DEFINE RADIOBUTTON FILERADIO OF THIS;
  392.        PROPERTY;
  393.          Width 9.666,;
  394.          FontBold .F.,;
  395.          Group .F.,;
  396.          Text "File",;
  397.          Top 6,;
  398.          Left 8,;
  399.          ColorNormal "B/BtnFace",;
  400.          OnChange CLASS::FILERADIO_ONCHANGE,;
  401.          PageNo 3,;
  402.          Value .F.,;
  403.          Height 1.1172
  404.  
  405.    DEFINE ENTRYFIELD FILENAMEENTRY OF THIS;
  406.        PROPERTY;
  407.          Width 32,;
  408.          FontBold .F.,;
  409.          Visible .F.,;
  410.          Top 6,;
  411.          Enabled .F.,;
  412.          Left 18,;
  413.          ColorNormal "B+/Window",;
  414.          PageNo 3,;
  415.          Value "FILENAMEENTRY",;
  416.          Height 1
  417.  
  418.    DEFINE TOOLBUTTON FILETOOLBUTTON OF THIS;
  419.        PROPERTY;
  420.          Width 4,;
  421.          Group .T.,;
  422.          Visible .F.,;
  423.          Top 6,;
  424.          Left 51,;
  425.          OnClick CLASS::FILETOOLBUTTON_ONCLICK,;
  426.          PageNo 3,;
  427.          Height 1
  428.  
  429.    DEFINE CHECKBOX ALLCOMPSCHECK OF THIS;
  430.        PROPERTY;
  431.          Width 30.833,;
  432.          FontBold .F.,;
  433.          Group .T.,;
  434.          Text "Create letters for all companies",;
  435.          Top 2.5,;
  436.          Left 0.5,;
  437.          ColorNormal "B/BtnFace",;
  438.          PageNo 3,;
  439.          Value .F.,;
  440.          Height 1.1465
  441.  
  442.    DEFINE PUSHBUTTON RUNMAILMERGEBUTTON OF THIS;
  443.        PROPERTY;
  444.          Width 14.166,;
  445.          Group .T.,;
  446.          Text "Mail Merge",;
  447.          Top 9.6973,;
  448.          SpeedTip "Run Word, and create letter",;
  449.          Left 24,;
  450.          OnClick CLASS::RUNMAILMERGEBUTTON_ONCLICK,;
  451.          PageNo 3,;
  452.          UpBitmap "RESOURCE #108",;
  453.          Height 1.5361
  454.  
  455.    DEFINE CHECKBOX PRINTPREVIEWCHECK OF THIS;
  456.        PROPERTY;
  457.          Width 31.666,;
  458.          FontBold .F.,;
  459.          Group .T.,;
  460.          Text "Preview Printed Document",;
  461.          Top 5,;
  462.          Enabled .F.,;
  463.          Left 18,;
  464.          ColorNormal "B/BtnFace",;
  465.          PageNo 3,;
  466.          Value .T.,;
  467.          Height 1
  468.  
  469.    DEFINE SAMPLEINFOBUTTON CONTACTINFOBUTTON OF THIS;
  470.        PROPERTY;
  471.          Width 3.5,;
  472.          Group .T.,;
  473.          Top 10,;
  474.          Left 0.5,;
  475.          Height 1.1758
  476.  
  477.    Procedure Form_OnOpen
  478.    ****************************************************************************
  479.  
  480.    form.wordApp = ""            && Reference to word
  481.  
  482.                                 && Default file name for saving Mail Merge doc
  483.    form.fileNameEntry.value = setto("directory") + "\Compltrs.doc"
  484.    form.contactInfoButton.sampleName = "Contact.wfm"
  485.    form.contactCloseButton.SetFocus()
  486.  
  487.  
  488.    ****************************************************************************
  489.  
  490.    Procedure Form_OnClose
  491.    ****************************************************************************
  492.  
  493.    if CLASS::IsWordOpen()                       && Word was left open
  494.       if ConfirmationMessage("Close Word, and discard latest changes?", "Confirm") = YES
  495.          form.wordApp.FileCloseAll(NO_SAVE)
  496.          form.wordApp.AppClose()
  497.       endif
  498.    endif
  499.  
  500.    close procedure &_dbwinhome.samples\Buttons.cc
  501.  
  502.  
  503.    ****************************************************************************
  504.  
  505.    Procedure CONTACTTABBOX_OnSelChange
  506.    ****************************************************************************
  507.  
  508.    form.pageNo = this.curSel
  509.  
  510.    ****************************************************************************
  511.  
  512.    Procedure FILERADIO_OnChange
  513.    ****************************************************************************
  514.  
  515.    if this.value
  516.       form.printerRadio.value = .F.
  517.       form.printPreviewCheck.visible = .F.
  518.  
  519.       form.fileNameEntry.visible = .T.
  520.       form.fileToolButton.visible = .T.
  521.    endif
  522.  
  523.  
  524.    ****************************************************************************
  525.  
  526.    Procedure PRINTERRADIO_OnChange
  527.    ****************************************************************************
  528.  
  529.    if this.value
  530.       form.fileRadio.value = .F.
  531.       form.fileNameEntry.visible = .F.
  532.       form.fileToolButton.visible = .F.
  533.  
  534.       form.printPreviewCheck.visible = .T.
  535.    endif
  536.  
  537.  
  538.    ****************************************************************************
  539.  
  540.    Procedure FILETOOLBUTTON_OnClick
  541.    ****************************************************************************
  542.    private fileName, name, extension, periodLoc
  543.  
  544.    fileName = putFile("Type the name of a file for saving merged letter(s)",;
  545.                       "*.doc")
  546.    if .not. empty(fileName)             && a name was actually selected
  547.       form.fileNameEntry.value = fileName
  548.       show object form.fileNameEntry
  549.    endif
  550.  
  551.    ****************************************************************************
  552.  
  553.    Procedure RUNMAILMERGEBUTTON_OnClick
  554.    ****************************************************************************
  555.    private destination, mergeRecords, recNo
  556.  
  557.    if empty(form.wordApp)               && Word has not been opened yet
  558.       if ConfirmationMessage("You must have a dBASE ODBC driver installed " +;
  559.                                 "for this mail merge to work properly. " +;
  560.                                 "Continue?",;
  561.                              "Confirm") = YES
  562.          on error AlertMessage(message(), "Sorry")
  563.          form.wordApp = new oleautoclient("word.basic")         && Open Word
  564.          on error
  565.          if empty(form.wordApp)
  566.             InformationMessage("You need to have MS Word 6.0 or greater " +;
  567.                                   "installed on your machine to run Mail Merge.",;
  568.                                "Sorry")
  569.          endif
  570.       endif
  571.    endif
  572.    if .not. empty(form.wordApp)         && Word has already been opened
  573.       if .not. CLASS::IsWordOpen()      && Make sure Word wasn't closed down
  574.          form.wordApp = new oleAutoClient("word.basic")
  575.       endif
  576.       if .not. CLASS::IsWindowOpen("COMPANY.DOC")
  577.          if .not. file("Company.doc")   && Make sure Company.doc exists
  578.             InformationMessage("Company.doc doesn't exist.  It is " +;
  579.                                   " necessary for running this Mail Merge.",;
  580.                                "Info")
  581.          else
  582.             form.wordApp.FileOpen("COMPANY.DOC")   && Open generic document
  583.          endif
  584.       endif
  585.       if CLASS::IsWindowOpen("COMPANY.DOC")        && If Company.doc was opened
  586.          form.wordApp.Activate("COMPANY.DOC")
  587.                                            && Attach Company.dbf as source
  588.          form.wordApp.MailMergeOpenDataSource("Company.dbf")
  589.          if form.allCompsCheck.value       && If letters to all companies
  590.             mergeAll = 0
  591.             recNo = 0
  592.          else
  593.             mergeAll = 1
  594.             recNo = recno()                && Only current Company
  595.          endif
  596.                                            && Set mail merge options
  597.          form.wordApp.MailMerge(REPORT_ERRORS, TO_FILE, mergeAll, recNo, recNo)
  598.          form.wordApp.MailMergeToDoc()     && Start with a file
  599.  
  600.          if form.printerRadio.value        && If printing letters
  601.             if ConfirmationMessage("Print Document?", "Confirm") = YES
  602.                form.wordApp.FilePrintDefault()     && Print with default options
  603.             endif
  604.          else                              && If saving to file
  605.             form.wordApp.FileSaveAs(form.fileNameEntry.value)
  606.          endif
  607.       endif
  608.    endif
  609.  
  610.  
  611.    ****************************************************************************
  612.  
  613.    Function IsWordOpen
  614.    ****************************************************************************
  615.    private fWordOpen
  616.  
  617.    fWordOpen = .F.
  618.    if .not. empty(form.wordApp)
  619.       * If Word was opened, and handle to it exists
  620.       if (type("form.wordApp.WdGetHWnd") <> "U") .and.;
  621.             (form.wordApp.WdGetHWnd() > 0)
  622.          fWordOpen = .T.
  623.       endif
  624.    endif
  625.  
  626.    return fWordOpen
  627.  
  628.  
  629.    ****************************************************************************
  630.  
  631.    Function IsWindowOpen(name)
  632.    ****************************************************************************
  633.    private windowOpen, i, windowCnt
  634.  
  635.    windowCnt = form.wordApp.CountWindows()
  636.    windowOpen = .F.
  637.    for i = 1 to windowCnt
  638.       if form.wordApp.WindowName(i) = name
  639.          windowOpen = .T.
  640.       endif
  641.    next i
  642.  
  643.    return windowOpen
  644.  
  645.  
  646. ENDCLASS
  647.  
  648.  
  649.  
  650.  
  651.  
  652.  
  653.